﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<c:if test="${type ==10 }">
  <link href="<%=basePath%>plugins/h_uiadmin_v2.3.4/css/H-ui.css" rel="stylesheet" type="text/css" />
</c:if>
<c:if test="${type !=10 }">
  <link href="<%=basePath%>plugins/h_uiadmin_v2.3.4/css/H-ui.min.css" rel="stylesheet" type="text/css" />
</c:if>
<link href="<%=basePath%>plugins/h_uiadmin_v2.3.4/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="<%=basePath%>plugins/h_uiadmin_v2.3.4/lib/Hui-iconfont/1.0.7/iconfont.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>产品管理</title>
</head>
<body>
<c:if test="${type !=10 }">
  <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 产品管理 <a class="btn btn-success btn-refresh radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:void(0);"  onclick="refresh();" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
</c:if>
<div class="pd-20">
 <form  id="queryForm" action="" method="post" class="form form-horizontal">
 <div class="row cl">
      <label class="form-label col-2">产品类型 ：</label>
      <div class="formControls col-4">
         <span class="select-box">
	            <select class="select"  size="1" id="productType" name="productType" >
			        <option value="0" selected="selected">请选择</option>
			       <c:if test="${productTypeList !=null}">
				       <c:forEach items="${productTypeList}" var="pl">
				        <option value="${pl.value}"> ${pl.description}</option>
				       </c:forEach>
			      </c:if>
			   </select>
		   </span>
      </div>
      <label class="form-label col-2">收益类型：</label>
      <div class="formControls col-4" >
          <span class="select-box">
	             <select class="select"  size="1" id="investType" name="investType" >
			        <option value="0" selected="selected">请选择</option>
			        <c:if test="${profitTypeList !=null}">
				       <c:forEach items="${profitTypeList}" var="pl">
				        <option value="${pl.value}"> ${pl.description}</option>
				       </c:forEach>
			      </c:if>
			   </select>
		   </span>
      </div>
    </div>
    
    <div class="row cl">
      <label class="form-label col-2">是否热销 ：</label>
      <div class="formControls col-4">
         <span class="select-box ">
           <select class="select"  size="1" id="isHot" name="isHot" >
		        <option value="-1" selected="selected">请选择</option>
		        <option value="1" >是</option>
		        <option value="0" >否</option>
		   </select>
		 </span>
      </div>
      <label class="form-label col-2">付息类型：</label>
      <div class="formControls col-4" >
          <span class="select-box">
            <select class="select"  size="1" id="paymentType" name="paymentType" >
		        <option value="0" selected="selected">请选择</option>
		         <c:if test="${paymentTypeList !=null}">
			       <c:forEach items="${paymentTypeList}" var="pl">
			        <option value="${pl.value}"> ${pl.description}</option>
			       </c:forEach>
		        </c:if>
		   </select>
		 </span>
      </div>
    </div>
 
   <div class="row cl">
      <label class="form-label col-2">状态 ：</label>
      <div class="formControls col-4">
          <span class="select-box">
            <select class="select"  size="1" id="status" name="status" >
		        <option value="0" selected="selected">请选择</option>
		        <c:if test="${statusList !=null}">
			       <c:forEach items="${statusList}" var="pl">
			        <option value="${pl.value}"> ${pl.description}</option>
			       </c:forEach>
		        </c:if>
		   </select>
		  </span>
      </div>
      <label class="form-label col-2">投资区域：</label>
      <div class="formControls col-4" >
           <input type="text" class="input-text" placeholder="" id="detailAddress" name="detailAddress" value="">
      </div>
    </div>
     <div class="row cl">
       <label class="form-label col-6"> </label>
       <div class="formControls col-6">
          <button type="button" class="btn btn-success radius" id="queryBtn" name="queryBtn"><i class="Hui-iconfont">&#xe665;</i> 搜产品</button>
       </div>
     </div>
	</form>

	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
		 <span class="l">
		  <c:if test="${type ==10 }">
		     <input id="selectProduct"  class="btn btn-primary radius" type="button" value="选择产品">
		  </c:if>
		  <c:if test="${type !=10 }">
		     <a href="javascript:;" onclick="add('新增','<%=basePath%>productmgr/toadd','','650')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 新增产品</a>
		 </c:if>
		</span> 
	</div>
	<div class="mt-20">
	<table id="resultTable" class="table table-striped table-border table-bordered " width="100%"> <!-- table  table-bordered table-bg table-hover  table-sort -->
		<thead>
			<tr class="text-c">
				<th width="">ID</th>
				<th width="">产品名称</th>
				<th width="">产品类型</th>
				<th width="">收益类型</th>
				<th width="">投资区域</th>
				<th width="">项目进度</th>
				<th width="">认购起点</th>
				<th width="">是否热销</th>
				<th width="">是否包分销</th>
				<th width="">付息类型</th>
				<th width="">状态</th>
				<th width="">添加时间</th>
				<th width="">更新时间</th>
				<th width="100">操作</th>
			</tr>
		</thead>
		<tbody>
		    <tr   >
				<td colspan="14"></td> 
			</tr>
		</tbody>
	</table>
	</div>
	
</div>
<script type="text/javascript" src="<%=basePath%>plugins/h_uiadmin_v2.3.4/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="<%=basePath%>plugins/h_uiadmin_v2.3.4/lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="<%=basePath%>plugins/h_uiadmin_v2.3.4/lib/laypage/1.2/laypage.js"></script> 

<script type="text/javascript" src="<%=basePath%>plugins/h_uiadmin_v2.3.4/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="<%=basePath%>plugins/h_uiadmin_v2.3.4/js/H-ui.js"></script> 
<script type="text/javascript" src="<%=basePath%>plugins/h_uiadmin_v2.3.4/js/H-ui.admin.js"></script> 
<script type="text/javascript" src="<%=basePath%>common/js/cms.js"></script> 
<script type="text/javascript" src="<%=basePath%>common/js/dt.ext.js"></script>
<script type="text/javascript">
$(function(){
	
	var resultTable = null ;
	function search(){
		resultTable = $('#resultTable').dataTable({
			// "aaSorting": [[ 1, "ASC" ]],//默认第几个排序
			//"bStateSave": false,//状态保存
			//"aoColumnDefs": [
			//  {"bVisible": false, "aTargets": [ 3 ]},  //控制列的隐藏显示
			//  {"orderable":false,"aTargets":[0]}// 制定列不参与排序 
			//] ,
			//"bAutoWidth":true  ,  // 自动宽度
			"ordering": true,
    		"info":     true ,
    		"searching":     false ,
    		"pagingType": "full_numbers" , // simple  simple_numbers  full  full_numbers 
    		"lengthMenu": [ 20,50, 100 ] ,
    		// "scrollY": 400,
            // "scrollX": false ,
			"processing": true,                    //加载数据时显示正在加载信息  
	        //"bServerSide": true,                    //指定从服务器端获取数据  
	        "serverSide": true,
	        "ajax": {
	               "url":"<%=basePath%>productmgr/query",
	               "data": function ( d ) {
	                   //添加额外的参数传给服务器
	                   d.extra_search = $("#queryForm").serialize();
	               }},
	        "columns": [
	                    { "data": "id" },
	                    { "data": "name" },
	                    { "data": "productTypeDesc" },
	                    { "data": "profitTypeDesc" },
	                    { "data": "detailAddress" },
	                    { "data": "collectProgress" },
	                    { "data": "subscribePoint" },
	                    { "data": "isHotDesc" }  ,
	                    { "data": "tagDesc" }  ,
	                    { "data": "paymentTypeDesc" }  ,
	                    { "data": "statusDesc" }  ,
	                    { "data": "createTimeDesc" }  ,
	                    { "data": "updateTimeDesc" }  ,
	                    { "data": null }  
	                  ] ,
	       "columnDefs": [ {
				    	   "targets": 1 ,
				    	   "data":null ,
				    	   render:function(a,b,c,d){
				    		     // if(c.status != 3)  // 下架
				    		      //  return '<a href="javascript:void(0)" style="color:red">'+c.name+'</a>' ;
				    		      return c.name ;    
				    	       }
				          },{
					    	   "targets": 10 ,
					    	   "data":null ,
					    	   render:function(a,b,c,d){
					    		      if(c.status == 3)  // 下架
					    		        return '<span class="label  radius">'+c.statusDesc+'</span>' ;
					    		      return '<span class="label label-success radiuslabel radius">'+c.statusDesc+'</span>' 
					    	       }
					      },
				          { "targets": 13,
	                        "data": null ,
	                         render: function (data,type,c,meta) {
	                        	var html = "" ;
	                        	<%
	                        	  String type = request.getParameter("type") ;
	                        	if(type !=null && type.equals("10")){
	                        	}
	                        	else{
	                        	  %>
	                        	     html += "<a  title=\"编辑\" href=\"javascript:void(0)\" onclick=\"edit('编辑', '"+c.id+"','','650');\" class=\"ml-5\" style=\"text-decoration:none\">编辑</a>" ;
			                    	 if(c.status == 2) {  // 募集结束
			                    	 }else if(c.status == 3){  // 下架 --再上架到
			                    		 html += "<a  title=\"上架\" href=\"javascript:void(0)\" onclick=\"product_upOrDown('上架', '"+c.id+"','','650');\" class=\"ml-5\" style=\"text-decoration:none\">上架</a>" ;
			                    	 }else {   // ==1 上架
			                    		 html += "<a  title=\"下架\" href=\"javascript:void(0)\" onclick=\"product_upOrDown('下架', '"+c.id+"','','650');\" class=\"ml-5\" style=\"text-decoration:none\">下架</a>" ;
			                    	 }  
	                        	  <%
	                        	}
	                        	%>
	                    	    
	                    	   return html;
	                      }  
	                     
	                  } ]
	         
		});
	}
	 
	  $('#queryBtn').click(function(){
	     resultTable.fnReloadAjax("<%=basePath%>productmgr/query?"+$("#queryForm").serialize()) ; 
		  
	});  
	
	 // init search 
	 search();
	 
	// 给每一行加一个事件 查看事件
	 $('#resultTable tbody').on('click','tr', function () {
		    // $(this).addClass("cursor:pointer") ;
		     if ( $(this).hasClass('selected') ) {
	            $(this).removeClass('selected');
	        }
	        else {
	        	resultTable.$('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        } 
		   
	 }); 
	
	/// 选择产品
	$("#selectProduct").click(function(){
		 var table = $('#resultTable').DataTable();   // 一定要先用这句取出对象 
	     var data = table.row('.selected').data();
		 if(data ==undefined || data == 'undefined'){
			 layer.msg("请选择一行产品",{icon:2,time:2000});
			 return ;
		 }
		 if(data.status == 3) {   // 下架 
				layer.msg("产品名称:"+data.name+"已下架,请重新选择!",{icon:2,time:2000});
				return 
			}
		 var index = parent.layer.getFrameIndex(window.name);
		 parent.setObject(data); 
		 parent.layer.close(index);
	});
		
});

/* 添加*/
function add(title,url,w,h){
	// layer_show(title,url,w,h);
	 var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);  
	
}
 
/* 编辑*/
function edit(title,id,w,h){
	 var url ="<%=basePath%>productmgr/toedit?productId="+id ;
	// layer_show(title,url,w,h);
	 var index = layer.open({
			type: 2,
			title: title,
			content: url
		});
		layer.full(index);  
}
 /*
 * 上下架
 */
function product_upOrDown(title ,id,w,h){
	layer.confirm('确认要'+title+'吗？',function(index){
		$.ajax({
			url:"<%=basePath%>productmgr/upordown" ,
			type:'POST',
			data:{'productId':id},
			dataType:'json',
			success:function(resp){
				 if(resp.success){
						  $('#queryBtn').click(); 
						  layer.msg('已'+title,{icon:1,time:1000});
				 }else{
					 layer.alert( resp.errMsg, {icon: 2},function(index){
						 layer.close(index);
					  });  
				 }
			}
		});
		
	});
}
/**
 * 刷新
 */
function refresh(){
	 location.replace(location.href);
}
</script> 
</body>
</html>